//package ocpp;
//
//import eu.chargetime.ocpp.ClientEvents;
//import eu.chargetime.ocpp.JSONClient;
//import eu.chargetime.ocpp.OccurenceConstraintException;
//import eu.chargetime.ocpp.UnsupportedFeatureException;
//import eu.chargetime.ocpp.feature.profile.ClientCoreEventHandler;
//import eu.chargetime.ocpp.feature.profile.ClientCoreProfile;
//import eu.chargetime.ocpp.model.core.*;
//
//import javax.net.ssl.*;
//import java.io.File;
//import java.io.FileInputStream;
//import java.security.KeyStore;
//import java.security.SecureRandom;
//import java.security.cert.CertificateException;
//import java.security.cert.X509Certificate;
//import java.util.concurrent.ExecutionException;
//
//public class OcppClient {
//
//    private static String storeType = "JKS";
//    private static String keyStore = "/xlocpp_2034_04_30.jks";
//    private static String storePassword =  "xlocpp123456";
//    private static String keyPassword ="xlocpp123456";
//
//    public static SSLContext buildSSLContext() throws Exception {
//        KeyStore ks = KeyStore.getInstance(storeType);
//        ks.load(new FileInputStream(new File("D:\\tangzhichao\\workspace\\dev_invoice_20231107\\electrombile\\xiaolancharging\\iotserver\\src\\main\\resources\\xlocpp_2034_04_30.jks")), storePassword.toCharArray());
//        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
//        kmf.init(ks, keyPassword.toCharArray());
//        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
//        tmf.init(ks);
//
//        SSLContext sslContext = null;
//        sslContext = SSLContext.getInstance( "TLS" );
//        sslContext.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null );
//        return sslContext;
////
////        SSLContext sslContext = SSLContext.getInstance("SSL");
////        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
////        return sslContext;
////
////        TrustManager[] trustAllCerts = new TrustManager[]{
////                new X509TrustManager() {
////                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
////                        return null;
////                    }
////                    public void checkClientTrusted(X509Certificate[] certs, String authType) {
////                    }
////                    public void checkServerTrusted(X509Certificate[] certs, String authType) {
////                    }
////                }
////        };
////        SSLContext sc = SSLContext.getInstance("SSL");
////        sc.init(null, trustAllCerts, new java.security.SecureRandom());
////        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
////
////        HostnameVerifier allHostsValid = new HostnameVerifier() {
////            public boolean verify(String hostname, SSLSession session) {
////                return true;
////            }
////        };
////
////
////        // set the  allTrusting verifier
////        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
////        return sc;
//    }
//
//
//    public static void main(String[] args) throws Exception {
//        ClientCoreEventHandler handler = new ClientCoreEventHandler() {
//            @Override
//            public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest(ChangeAvailabilityRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted);
//            }
//
//            @Override
//            public GetConfigurationConfirmation handleGetConfigurationRequest(GetConfigurationRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public ChangeConfigurationConfirmation handleChangeConfigurationRequest(ChangeConfigurationRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public ResetConfirmation handleResetRequest(ResetRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//
//            @Override
//            public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request) {
//
//                System.out.println(request);
//                // ... handle event
//
//                return null; // returning null means unsupported feature
//            }
//        };
//        ClientCoreProfile clientCoreProfile = new ClientCoreProfile(handler);
//        JSONClient jsonClient = new JSONClient(clientCoreProfile );
////        jsonClient.enableWSS(buildSSLContext());
//        String url = "ws://192.168.1.97:8889";
//
//
//
//        AuthorizeRequest testRequest = clientCoreProfile.createAuthorizeRequest("testId");
//        jsonClient.connect(url, new ClientEvents() {
//            @Override
//            public void connectionOpened() {
//                System.out.println("连接进来了");
//            }
//
//            @Override
//            public void connectionClosed() {
//                System.out.println("连接断开了");
//            }
//        });
//
//        try {
//            AuthorizeConfirmation authorizeConfirmation = (AuthorizeConfirmation) jsonClient.send(testRequest)
//                    .toCompletableFuture().get();
//            System.out.println(authorizeConfirmation);
//        } catch (OccurenceConstraintException | UnsupportedFeatureException
//                 | ExecutionException | InterruptedException e) {
//            e.printStackTrace();
//        }
//    }
//}
